Page({
  data: {
    dialogVisible: false,
    HouseList: [],
    id: '',
    //定义枚举
    statusMsg: {
      1: '审核中',
      2: '审核通过',
      3: '审核失败'
    },
    //定义枚举类型
    statusType: {
      1: 'info',
      2: 'success',
      3: 'fail'
    }
  },

  onShow() {
    //获取房屋列表
    this.getHouseList()
    this.getLocation()
  },
  //获取经纬度
  async getLocation() {
    const res = await wx.getLocation()
    console.log('经纬度', res.latitude, res.longitude);
  },
  //获取房屋列表
  async getHouseList() {
    const res = await wx.http.get('/room')
    // console.log('房屋列表', res);
    this.setData({
      HouseList: res.data
    })
  },
  //删除单个房屋
  deleteRoom(id) {
    wx.http.delete(`/room/${id}`)
  },
  //删除房屋
  async dialogClose(e) {
    // console.log('111', e);
    if (e.detail === 'confirm') {
      //调用删除单个房屋方法
      await this.deleteRoom(this.data.id)
      //删除成功提示用户
      wx.utils.toast('删除成功')
      //重新获取数据
      this.getHouseList()
    }
  },
  swipeClose(ev) {
    // console.log(ev, 555555);
    this.setData({
      id: ev.mark.id
    })
    const { position, instance } = ev.detail

    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })

      // swiper-cell 滑块关闭
      instance.close()
    }
  },
  //点击跳转到指定的页面
  goDetail(e) {
    console.log(e);
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + e.mark.id,
    })
  },
  //添加房屋
  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
